package core.manager
{
    import core.manager.pluginManager.*;
    import core.manager.scriptManager.*;
    
    import flash.events.*;

    public class MainSystem extends EventDispatcher
    {
        public var _isBusy:Boolean = false;
        private var oldBusyState:Boolean = false;
        private static var instance:MainSystem;

        public function MainSystem()
        {
            if (instance == null)
            {
                super(this);
                instance = this;
            }
            else
            {
                throw new Error("ScriptManager不能被实例化");
            }
            return;
        }// end function

        public function get isBusy() : Boolean
        {
            return _isBusy;
        }// end function

        public function set isBusy(styleChangedFlag:Boolean) : void
        {
            _isBusy = styleChangedFlag;
            return;
        }// end function

        public function removePluginById(styleChangedFlag:String) : void
        {
            PluginManager.getInstance().removePluginById(styleChangedFlag);
            return;
        }// end function

        public function runAPIDirectDirectly(name:String, array:Array = null):*
        {
            return ScriptManager.getInstance().runScriptByName(name,array );
        }// end function

        public function runScript(s:String):*
        {
            return ScriptManager.getInstance().runScriptDirectly(s);
        }// end function

        public function showPluginById(styleChangedFlag:String) : void
        {
            PluginManager.getInstance().showPluginById(styleChangedFlag);
            return;
        }// end function

        public function runAPI(name:String,array:Array = null):*
        {
            if (MainSystem.getInstance().isBusy)
            {
                return;
            }
            return ScriptManager.getInstance().runScriptByName(name,array );
        }// end function

        public static function getInstance() : MainSystem
        {
            if (instance == null)
            {
                return new MainSystem;
            }
            return instance;
        }// end function

    }
}
